﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace cubeworld
{
    public class Functions
    {
        public static Ray CalculateCursorRay()
        {
            Vector2 mousePos = new Vector2(MainGame.Device.Viewport.Width * 0.5f, MainGame.Device.Viewport.Height * 0.5f);

            Vector3 nearSource = new Vector3(mousePos, 0f);
            Vector3 farSource = new Vector3(mousePos, 1f);

            Vector3 nearPoint = MainGame.Device.Viewport.Unproject(nearSource,
                Data.camera.projection, Data.camera.view, Matrix.Identity);

            Vector3 farPoint = MainGame.Device.Viewport.Unproject(farSource,
                Data.camera.projection, Data.camera.view, Matrix.Identity);

            Vector3 direction = farPoint - nearPoint;
            direction.Normalize();

            return new Ray(nearPoint, direction);
        }

        public static bool existWorld()
        {
            string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\save.world";
            return System.IO.File.Exists(path);
        }
    }
}
